Programmatically finding the process template used in a project
How do I programmaticlly find out the process template used in a project through Reportable Rest API. If no methods are available in Reportable Rest API please suggest using RTC SDK.
5 answers
here is some code I used to find the process source, even if it was from a parent project
static String keyname = com.ibm.team.process.common.ProcessContentKeys.PROCESS_SPECIFICATION_KEY;
<code>
need to get access to the internal method to get the parent
import com.ibm.team.process.internal.common.impl.ProjectAreaImpl;
if ((repo=login(url, userid, password, sPm)) != null )
{
// get the content Manager
IContentManager icm = repo.contentManager();
// get the list of projects
// * means all
// specific name means only that one.. case sensitive I think
List<IProjectArea> projectList = getProjectArea(repo, sPm,
ProjectType);
System.out.println(" there are " + projectList.size()
+ " projects");
// loop thru the list of projects, if any
for (int i = 0; i < projectList.size(); i++)
{
// get the project area
IProjectArea ip = projectList.get(i);
// if the project is not archived
if(!ip.isArchived())
{
System.out.println("\nproject name = " + ip.getName());
IItem ipi = ip.getWorkingCopy();
// call the internal only method to get the parent process
// provider.. if any
IProjectAreaHandle iparenthandle = ((ProjectAreaImpl) ipi)
.getProcessProvider();
// if there was a parent
if (iparenthandle != null)
{
// get it
IProjectArea parentProject = (IProjectArea) (repo
.itemManager().fetchCompleteItem(iparenthandle,
IItemManager.DEFAULT, sPm));
System.out.println("have parent project name = "
+ parentProject.getName());
// get the process data
@SuppressWarnings("unchecked")
Map<String, Object> pd = ip.getProcessData();
//// here is the xml extract
// get the process config content object
IContent processSource = (IContent) pd.get(keyname);
if (processSource != null)
{
System.out.println("have xml source");
saveXMLSource(ip, processSource, icm, sPm);
}
</code>
saving the xml source
<code>
private static void saveXMLSource(IProjectArea ip, IContent ic,
IContentManager icm, SysoutProgressMonitor sPm)
{
// make an output stream for the content manager
OutputStream os = new ByteArrayOutputStream();
// get the content of the content object.
try
{
icm.retrieveContent(ic, os, sPm);
// write xml content to file
// project name + data name
FileOutputStream fo = new FileOutputStream(ip.getName() + "."
+ keyname);
// write
fo.write(os.toString().getBytes(), 0, os.toString().length());
// close
fo.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
</code>
find the (or list of projects)
<code>
public static List<IProjectArea> getProjectArea(ITeamRepository repo,
IProgressMonitor monitor, String projectAreaName)
throws TeamRepositoryException
{
List<IProjectArea> projectareaonly = new ArrayList<IProjectArea>();
@SuppressWarnings("unchecked")
// get all the projects in this repository
List<IProjectArea> projectAreas = getProcessItemService(repo)
.findAllProjectAreas(null, monitor);
// if Not ALL projects
if (!projectAreaName.equalsIgnoreCase("*"))
{
for (int i = 0; i < projectAreas.size(); i++)
{
// get next project from array
IProjectArea projectArea = projectAreas.get(i);
// if the names are equal, case sensitive
if (projectArea.getName().equals(projectAreaName))
{
// return this one project to the caller
System.out.println("Found " + projectAreaName);
projectareaonly.add(projectArea);
break;
}
else if (i + 1 == projectAreas.size())
{
System.out.println("Failed to find requested project '"
+ projectAreaName + "'");
}
}
return projectareaonly;
}
else
projectareaonly = projectAreas;
return projectareaonly;
}
</code>
static String keyname = com.ibm.team.process.common.ProcessContentKeys.PROCESS_SPECIFICATION_KEY;
<code>
need to get access to the internal method to get the parent
import com.ibm.team.process.internal.common.impl.ProjectAreaImpl;
if ((repo=login(url, userid, password, sPm)) != null )
{
// get the content Manager
IContentManager icm = repo.contentManager();
// get the list of projects
// * means all
// specific name means only that one.. case sensitive I think
List<IProjectArea> projectList = getProjectArea(repo, sPm,
ProjectType);
System.out.println(" there are " + projectList.size()
+ " projects");
// loop thru the list of projects, if any
for (int i = 0; i < projectList.size(); i++)
{
// get the project area
IProjectArea ip = projectList.get(i);
// if the project is not archived
if(!ip.isArchived())
{
System.out.println("\nproject name = " + ip.getName());
IItem ipi = ip.getWorkingCopy();
// call the internal only method to get the parent process
// provider.. if any
IProjectAreaHandle iparenthandle = ((ProjectAreaImpl) ipi)
.getProcessProvider();
// if there was a parent
if (iparenthandle != null)
{
// get it
IProjectArea parentProject = (IProjectArea) (repo
.itemManager().fetchCompleteItem(iparenthandle,
IItemManager.DEFAULT, sPm));
System.out.println("have parent project name = "
+ parentProject.getName());
// get the process data
@SuppressWarnings("unchecked")
Map<String, Object> pd = ip.getProcessData();
//// here is the xml extract
// get the process config content object
IContent processSource = (IContent) pd.get(keyname);
if (processSource != null)
{
System.out.println("have xml source");
saveXMLSource(ip, processSource, icm, sPm);
}
</code>
saving the xml source
<code>
private static void saveXMLSource(IProjectArea ip, IContent ic,
IContentManager icm, SysoutProgressMonitor sPm)
{
// make an output stream for the content manager
OutputStream os = new ByteArrayOutputStream();
// get the content of the content object.
try
{
icm.retrieveContent(ic, os, sPm);
// write xml content to file
// project name + data name
FileOutputStream fo = new FileOutputStream(ip.getName() + "."
+ keyname);
// write
fo.write(os.toString().getBytes(), 0, os.toString().length());
// close
fo.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
</code>
find the (or list of projects)
<code>
public static List<IProjectArea> getProjectArea(ITeamRepository repo,
IProgressMonitor monitor, String projectAreaName)
throws TeamRepositoryException
{
List<IProjectArea> projectareaonly = new ArrayList<IProjectArea>();
@SuppressWarnings("unchecked")
// get all the projects in this repository
List<IProjectArea> projectAreas = getProcessItemService(repo)
.findAllProjectAreas(null, monitor);
// if Not ALL projects
if (!projectAreaName.equalsIgnoreCase("*"))
{
for (int i = 0; i < projectAreas.size(); i++)
{
// get next project from array
IProjectArea projectArea = projectAreas.get(i);
// if the names are equal, case sensitive
if (projectArea.getName().equals(projectAreaName))
{
// return this one project to the caller
System.out.println("Found " + projectAreaName);
projectareaonly.add(projectArea);
break;
}
else if (i + 1 == projectAreas.size())
{
System.out.println("Failed to find requested project '"
+ projectAreaName + "'");
}
}
return projectareaonly;
}
else
projectareaonly = projectAreas;
return projectareaonly;
}
</code>
I really want to find a way using REST API, how I can find "Process template" in particular project area?
Please let me know if somebody knows how to get handle to process templates using REST API's
Somebody in comment section said its not available.But still want to confirm
Thanks in advance!
Please let me know if somebody knows how to get handle to process templates using REST API's
Somebody in comment section said its not available.But still want to confirm
Thanks in advance!
Al-right thanks for the answer Sam and Qiong!
I have another question since obvious option is RTC SDK now
If we use RTC SDK is there a way to create workitems in RTC using process templates programatically? similar to the way we do it in RTC UI manually?
I appreciate your help in this regard!
Thanks,
Harshal
I have another question since obvious option is RTC SDK now
If we use RTC SDK is there a way to create workitems in RTC using process templates programatically? similar to the way we do it in RTC UI manually?
I appreciate your help in this regard!
Thanks,
Harshal
Comments
Geoffrey Clemm
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER May 02 '13, 1:01 p.m.By "process template", do you mean the XML process configuration source for a specified project area?
Praveen Kumar
May 03 '13, 2:34 a.m.Yes. I am talking about the "Process/Project Template" that is used while creating the project. For example while creating a life cycle project we select "Scrum" as the "Project template". I am looking for an API REST or SDK using which I can retrieve the "Project template" name. In this case "Scrum"
Qiong Feng Huang
JAZZ DEVELOPER unknownIt's simple if you just want to get the name of the process template. Suppose you have got an instance of IProjectArea, you can use IProjectArea.getProcessDefinition() to get the handle of the process template, then you can use IRepositoryItemService.fetchItem() to get the instance of this process template.
Qiong Feng Huang
JAZZ DEVELOPER May 03 '13, 8:33 a.m.It's simple if you just want to get the name of the process template. Suppose you have got an instance of IProjectArea, you can use IProjectArea.getProcessDefinition() to get the handle of the process template, then you can use IRepositoryItemService.fetchItem() to get the instance of this process template.
Praveen Kumar
May 06 '13, 1:11 a.m.If we use RTC SDK, the below suggestion from @sam detweiler works. What if I want to use Rest API. Can I find the "Process/Project Template" using reportable rest API
sam detweiler
May 06 '13, 7:22 a.m.far as I know this data is not available thru the REST api
(I had to use an internal class to get access to the parent if any)